package com.shenfa.action.tree;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;
import com.shenfa.bean.PaperCityCrd;
import com.shenfa.bean.TreeNode;
import com.shenfa.bean.TreeNodeCheck;
import com.shenfa.service.CityService;
import com.shenfa.service.EpibCityService;
import com.shenfa.service.ProductService;
import com.shenfa.service.systemManager.SystemService;

public class TreeCheckAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Autowired
	private SystemService systemService;

	@Autowired
	private ProductService productService;
	
	@Autowired
	private EpibCityService epibCityService;
	@Autowired
	private CityService cityService;
	

	private static Logger log=Logger.getLogger(TreeCheckAction.class);
	
	private String node;

	private String cardid;
	
	private PaperCityCrd paperCityCrd;

	private List<TreeNodeCheck> nodes;

	/**
	 * 获取功能树
	 * 
	 * @return
	 */
	public String rolefunc() {
		//查询角色的功能列表
		log.debug("node="+node);
		if("root".equals(node)){
			nodes=systemService.getListByRolePid("0");
		}else{
			nodes=systemService.getListByRolePid(node);
		}
		return SUCCESS;
	}

	/**
	 * 获取城市树
	 * 
	 * @return
	 */
	public String cardCity() {
		nodes = new ArrayList<TreeNodeCheck>();
		log.debug("node="+node);
		if(null == node || "".equals(node) || "root".equals(node)){
			node="0";
		}
		nodes = productService.doLsitByCardid(node, cardid);
		return SUCCESS;
	}
	
	
	/**
	 * 查询指定卡产品及预印纸对应的发行城市树
	 * 
	 * @author yanglong
	 */
	public String cardCity1() {
		log.debug("paperNo="+paperCityCrd.getPaper_no()+",cardNo="+paperCityCrd.getCard_no()+",businpntNo="+paperCityCrd.getBusinpnt_no());
		if(null != paperCityCrd){
			nodes = epibCityService.queryTreeList1(paperCityCrd);
		}
		return SUCCESS;
	}
	
	/**
	 * 查询指定卡产品及外包商对应的发行城市树
	 * 
	 * @author yanglong
	 */
	public String epibCity() {
		log.debug("paperNo="+paperCityCrd.getPaper_no()+",cardNo="+paperCityCrd.getCard_no()+",businpntNo="+paperCityCrd.getBusinpnt_no());
		if(null != paperCityCrd){
			nodes = epibCityService.queryTreeList(paperCityCrd);
			
		}
		return SUCCESS;
	}
	/**
	 * 查询城市树结构
	 * @return
	 */
	public String city(){
		if(node==null || node.equals("") || node.equals("root")){
			nodes=cityService.queryCheckTree("0");
		}else{
			nodes=cityService.queryCheckTree(node);
		}
		
		return SUCCESS;
	}
	
	public void setNode(String node) {
		this.node = node;
	}

	public List<TreeNodeCheck> getNodes() {
		return nodes;
	}

	public void setCardid(String cardid) {
		this.cardid = cardid;
	}

	public PaperCityCrd getPaperCityCrd() {
		return paperCityCrd;
	}

	public void setPaperCityCrd(PaperCityCrd paperCityCrd) {
		this.paperCityCrd = paperCityCrd;
	}
	
}
